package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.IWorkLogBiz;
import com.cloudservice.ccs.entity.WorkLog;
import com.cloudservice.ccs.exception.WorkLogException;
import com.cloudservice.ccs.mapper.WorkLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorkLogImpl implements IWorkLogBiz {
    @Autowired
    private WorkLogMapper workLogMapper;

    @Override
    public void save(WorkLog workLog) {
        int res = workLogMapper.save(workLog);
        if (res == 0) {
            throw new WorkLogException("Create WorkLog failed");
        }
    }

    @Override
    public void update(Integer id, WorkLog workLog) {
        int res = workLogMapper.update(id, workLog);
        if (res == 0) {
            throw new WorkLogException("Update WorkLog failed");
        }
    }

    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int res = workLogMapper.partialUpdate(id, fields);
        if (res == 0) {
            throw new WorkLogException("Partial update WorkLog failed");
        }
    }

    @Override
    public void delete(Integer id) {
        int res = workLogMapper.delete(id);
        if (res == 0) {
            throw new WorkLogException("Delete WorkLog failed");
        }
    }

    @Override
    public WorkLog getOne(Integer id) {
        WorkLog workLog = workLogMapper.getOne(id);
        if (workLog == null) {
            throw new WorkLogException("Requested WorkLog does not exist");
        }
        return workLog;
    }

    @Override
    public List<WorkLog> getAll() {
        return workLogMapper.getAll();
    }
}
